using System;
using System.Collections.Generic;
using ilgolosone.Shared.IoC;
using Microsoft.Practices.Unity;

namespace ilgolosone.DependencyResolver.Unity
{
    public class UnityDependencyResolver : IDependencyResolver
    {
        private readonly IUnityContainer _container;

        public UnityDependencyResolver(IUnityContainer container)
        {
            if (container == null) throw new ArgumentNullException("container");
            
            _container = container;
        }

        public TService Resolve<TService>()
        {
            return _container.Resolve<TService>();
        }

        public TService Resolve<TService>(string key)
        {
            return _container.Resolve<TService>(key);
        }

        public IEnumerable<TService> ResolveAll<TService>()
        {
            return _container.ResolveAll<TService>();
        }

        public void Dispose()
        {
            // Unity ha bisogno di disposing....
            _container.Dispose();
        }
    }
}